const { http } = uni.$u;

const make_add_function = () => {
  let id = 1;
  return () => {
    return id++;
  };
};
const add_id = make_add_function();
const formatParams = (params) => {
  let id = add_id();
  let data = {
    jsonrpc: "2.0",
    id: id,
    params: params,
  };
  return data;
};

// export const get_session_info = (params, config = {}) => http.post('/session/get_session_info', params, config)

export const get_session_info = (params, config = {}) => {
  let data = formatParams(params);
  return http.post("/session/get_session_info", data, config);
};

//# 1 采购审批单列表
export const purchase_request_record = (params, config = {}) => {
  let data = formatParams(params);
  return http.post("/purchase/purchase_request_record", data, config);
};
// # 2 单一采购审批单明细
export const purchase_record_detail = (params, config = {}) => {
  let data = formatParams(params);
  return http.post("/purchase/purchase_record_detail", data, config);
};
//# 3 厨师长直接下单采购，不需要采购审批
export const chef_direct_place_po = (params, config = {}) => {
  let data = formatParams(params);
  return http.post("/purchase/chef_direct_place_po", data, config);
};

// # 3  采购审批 同意、拒绝
export const purchase_record_approve = (params, config = {}) => {
  let data = formatParams(params);
  return http.post("/purchase/purchase_record_approve", data, config);
};
//# 4  点击添加按钮 生成采购单
export const purchase_request_draft = (params, config = {}) => {
  let data = formatParams(params);
  return http.post("/purchase/purchase_request_draft", data, config);
};
// # 5 点击 窗口明细 按钮
export const purchase_request_edit = (params, config = {}) => {
  let data = formatParams(params);
  return http.post("/purchase/purchase_request_edit", data, config);
};
// # 6 点击 保存 按钮
export const purchase_request_require_handin = (params, config = {}) => {
  let data = formatParams(params);
  return http.post("/purchase/purchase_request_require_handin", data, config);
};

//# 7 点击 提交 按钮
//# id=0表示前端创建的新采购申请单
export const purchase_record_handin = (params, config = {}) => {
  let data = formatParams(params);
  return http.post("/purchase/purchase_record_handin", data, config);
};

// # 8 点击 删除 按钮，只有【草稿】和【拒绝】状态的采购单才能删除。
// data = {'pr_id': pr_id,
//         }
export const purchase_request_delete = (params, config = {}) => {
  let data = formatParams(params);
  return http.post("/purchase/purchase_request_delete", data, config);
};

// # 1 厨师长采购单列表
// # org_po_record  采购单
// # org_po_detail  采购详情
// # org_pr_record   采购申请单
// # org_pr_record   采购申请详情
export const po_pr_record = (params, config = {}) => {
  let data = formatParams(params);
  return http.post("/purchase/po_pr_record", data, config);
};

// # 3 把分部门的采购申请合并，转换为公共mm_id数据
export const pr_groupby_and_convert = (params, config = {}) => {
  let data = formatParams(params);
  return http.post("/purchase/pr_groupby_and_convert", data, config);
};
// # 5 采购员看到的界面
export const org_pr_list = (params, config = {}) => {
  let data = formatParams(params);
  return http.post("/purchase/org_pr_list", data, config);
};
// # 7 采购员下单
export const purchaser_place_order = (params, config = {}) => {
  let data = formatParams(params);
  return http.post("/purchase/purchaser_place_order", data, config);
};

// 登录
export const login = (params, config = {}) =>
  http.post("/login", params, config);
// 登录
export const login_new = (params, config = {}) =>
  http.post("/login_new", params, config);

// # 1 日成本销售报表
export const day_kpi_report = (params, config = {}) => {
  let data = formatParams(params);
  return http.post("/report/day_kpi_report", data, config);
};
// # 2 日成本销售明细
export const one_day_kpi_report_detail = (params, config = {}) => {
  let data = formatParams(params);
  return http.post("/report/one_day_kpi_report_detail", data, config);
};
// # 3 保存日成本销售明细
export const save_one_day_sales_cost_detail = (params, config = {}) => {
  let data = formatParams(params);
  return http.post("/report/save_one_day_sales_cost_detail", data, config);
};

// #  创建
export const common_create = (params, config = {}) => {
  let data = formatParams(params);
  return http.post("/common_create", data, config);
};
// #  修改
export const common_write = (params, config = {}) => {
  let data = formatParams(params);
  return http.post("/common_write", data, config);
};

// 仓管接口
// 仓管首页数据
export const getStock = (params) => {
	const data = formatParams(params);
  return http.post("/stock/stock", data);
};
// 仓管食品单个Id数据
export const stock_in_out_detail_one_material = (params) => {
  const data = formatParams(params);
  return http.post("/stock/stock_in_out_detail_one_material", data);
};
export const stock_change = (params) => {
	const data = formatParams(params);
  return http.post("/stock/stock_change", data);
};

// 待入库列表
export const stock_in_and_to_be_stock_in= (params) => {
  const data = formatParams(params);
  return http.post("/stock/stock_in_and_to_be_stock_in", data);
};

//  入库明细列表，在库存页点击一个食材后显示此食材
export const stock_in_record_detail= (params) => {
  const data = formatParams(params);
  return http.post("/stock/stock_in_record_detail", data);
};


// # # 4 点击 新建 按钮，拉取食材等基础数据给前端
export const create_new_stock_in= (params) => {
  const data = formatParams(params);
  return http.post("/stock/create_new_stock_in", data);
};

/**
 * 库存页面的 出库中的  出库记录 
 */

export const stock_out_record= (params) => {
  const data = formatParams(params);
  return http.post("/stock/stock_out_record", data);
};


/**
 * 
 * @param {*} 选择出库食材 数据
 * @returns  
 */
export const new_stock_out= (params) => {
  const data = formatParams(params);
  return http.post("/stock/new_stock_out", data);
};

// 待入库 编辑入库
export const to_be_stock_one_supplier_detail= (params) => {
  const data = formatParams(params);
  return http.post("/stock/to_be_stock_one_supplier_detail", data);
};

/**
 * 出库提交
 */
export const confirm_to_stock_out= (params) => {
  const data = formatParams(params);
  return http.post("/stock/confirm_to_stock_out", data);
};


/**
 * 
 * @param {*} params 
 * @param {*} 
 * @returns 
 */
//盘点 详情
export const stock_taking_record= (params) => {
  const data = formatParams(params);
  return http.post("/stock/stock_taking_record", data);
};

/**
 * 
 * @param {*} params 
 * @param {*} 
 * @returns 
 */
// 单个盘点
export const one_stock_taking_record_detail= (params) => {
  const data = formatParams(params);
  return http.post("/stock/one_stock_taking_record_detail", data);
};
// 点击 新增 按钮 盘点
export const new_stock_taking_record= (params) => {
  const data = formatParams(params);
  return http.post("/stock/new_stock_taking_record", data);
};
// #  删除
export const common_delete = (params, config = {}) => {
	let data = formatParams(params);
	return http.post('/common_delete',  data, config)
}
export const update_cost_report_data = (params, config = {}) => {
	let data = formatParams(params);
	return http.post('/report/update_cost_report_data',  data, config)
}

// # 8 采购单分享
export const share_po = (params, config = {}) => {
	let data = formatParams(params);
	return http.post('/purchase/share_po',  data, config)
}

// # 入库
export const confirm_stock_in = (params, config = {}) => {
	let data = formatParams(params);
	return http.post('/stock/confirm_stock_in',  data, config)
}
export const manual_stock_in = (params, config = {}) => {
	let data = formatParams(params);
	return http.post('/stock/manual_stock_in',  data, config)
}
// # 18 盘点结果处置
export const stock_taking_record_handle_diff = (params, config = {}) => {
	let data = formatParams(params);
	return http.post('/stock/stock_taking_record_handle_diff',  data, config)
}
// 9 出库记录明细
export const one_stock_out_record_detail = (params, config = {}) => {
	let data = formatParams(params);
	return http.post('/stock/one_stock_out_record_detail',  data, config)
}

// 12 在 出库申请 页面，点击“出库” 按钮，准备出库
export const stock_out_app_detail = (params, config = {}) => {
	let data = formatParams(params);
	return http.post('/stock/stock_out_app_detail',  data, config)
}
 // 13 驳回出库申请
export const stock_out_app_reject = (params, config = {}) => {
	let data = formatParams(params);
	return http.post('/stock/stock_out_app_reject',  data, config)
}


// # 8 食材创建
export const material_create = (params, config = {}) => {
	let data = formatParams(params);
	return http.post('/purchase/material_create',  data, config)
}
// # 8 食材修改
export const material_write = (params, config = {}) => {
	let data = formatParams(params);
	return http.post('/purchase/material_write',  data, config)
}
// # 2-3 新创建食材或查看、修改食材详情，把关联的外键表发送到前端。这个数据量小，可随时调用
export const material_create_edit = (params, config = {}) => {
	let data = formatParams(params);
	return http.post('/purchase/material_create_edit',  data, config)
}

export const toggle_po_record_detail_status = (params, config = {}) => {
	let data = formatParams(params);
	return http.post('/purchase/toggle_po_record_detail_status',  data, config)
}
// # 2-1 这个只是拉取食材，没有其他数据
export const purchase_material_item = (params, config = {}) => {
	let data = formatParams(params);
	return http.post('/purchase/material_item', data, config)
}
// # 2-2 这是食材分类数据，前端需要做缓存，不需要每次都拉数据
export const material_static_data = (params, config = {}) => {
	let data = formatParams(params);
	return http.post('/purchase/material_static_data', data, config)
}

// ↓↓↓菜单
// # 1 菜品食材公共数据，前端缓存
export const dish_material_common_data = (params, config = {}) => {
	let data = formatParams(params);
	return http.post('/plan/dish_material_common_data', data, config)
}
// # 1 当前用户可以看到的模板
export const plan_week_model_overall_show = (params, config = {}) => {
	let data = formatParams(params);
	return http.post('/plan/plan_week_model_overall_show', data, config)
}

// 上传文件
export const upload = (filePath, config = {}) => {
	// let data = formatParams(params);
	return http.upload('/upload', {
		filePath:filePath
	}, config)
}
// 语音录入 历史记录
export const user_input_detail_history = (params, config = {}) => {
	let data = formatParams(params);
	return http.post('/report/user_input_detail_history', data, config)
}
// 销售设置
export const sales_cfg = (params, config = {}) => {
	let data = formatParams(params);
	return http.post('/report/sales_cfg', data, config)
}

// 分餐
export const get_plan_day_distribution_data = (params, config = {}) => {
	let data = formatParams(params);
	return http.post('/report/get_plan_day_distribution_data', data, config)
}
// 更新分餐
export const update_plan_day_distribution_data = (params, config = {}) => {
	let data = formatParams(params);
	return http.post('/report/update_plan_day_distribution_data', data, config)
}
// 上传图片
export const upload_attachment = (filePath,params,config = {}) => {
	return http.upload('/binary/upload_attachment',{
		filePath:filePath,
		name: 'ufile',
		formData:params
	})
}
//删除图片
export const unlink_attachment = (params, config = {}) => {
	let data = formatParams(params);
	return http.post('/binary/unlink_attachment', data, config)
}

// 流程检查

// 检查表列表
export const sop_review_list = (params, config = {}) => {
	let data = formatParams(params);
	return http.post('/process_check/sop_review_list', data, config)
}
// 检查结果列表
export const get_one_sop_review_record = (params, config = {}) => {
	let data = formatParams(params);
	return http.post('/process_check/get_one_sop_review_record', data, config)
}
// 检查结果详情
export const get_one_sop_review_detail = (params, config = {}) => {
	let data = formatParams(params);
	return http.post('/process_check/get_one_sop_review_detail', data, config)
}
// 用户点击检查
export const get_or_create_one_sop_review = (params, config = {}) => {
	let data = formatParams(params);
	return http.post('/process_check/get_or_create_one_sop_review', data, config)
}


// 菜品计划
export const plan_day_cus_dish_allocation = (params, config = {}) => {
	let data = formatParams(params);
	return http.post('/plan_day/plan_day_cus_dish_allocation', data, config)
}
export const plan_day_save_cus_dish_allocation = (params, config = {}) => {
	let data = formatParams(params);
	return http.post('/plan_day/plan_day_save_cus_dish_allocation', data, config)
}
export const plan_day_cus_dish_allocation_common_data = (params, config = {}) => {
	let data = formatParams(params);
	return http.post('/plan_day/plan_day_cus_dish_allocation_common_data', data, config)
}
export const plan_day_save_cus_dinner_mode = (params, config = {}) => {
	let data = formatParams(params);
	return http.post('/plan_day/plan_day_save_cus_dinner_mode', data, config)
}